﻿
using MyFloridaHouse.libSvOpenDistricts.Dialogs;
using MyFloridaHouse.libSvCommonUtilities;
using MyFloridaHouse.libSvOpenDistricts.Criteria;
using MyFloridaHouse.libSvUtilities.Logging;
using System;
namespace MyFloridaHouse.libSvOpenDistricts.ViewModel
{
    public partial class ViewModelBase
    {
        public PrefCustomizeCriteriaDlg prefCustomizeCriteriaDlg;

        private bool CmdPrefCriteriaCanExecute(object parameter)
        {
            return (!isDialogOpen);
        }

        private void CmdPrefCriteriaExecute(object parameter)
        {
            try
            {
                ReserveDialog(CmdPrefCriteria);
                prefCustomizeCriteriaDlg = new PrefCustomizeCriteriaDlg(OnMemberPropertyChanged, DisplayPanelForDialogs);
                prefCustomizeCriteriaDlg.Start(prefCustomizeCriteriaDlgDone);
                prefCustomizeCriteriaDlg.Reset(CriteriaDatasetManager.GetDatasetNames(), dataGridManager.criteriaDatasetName, regionLabel.criteriaDatasetName, regionFill.criteriaDatasetName);
            }
            catch (Exception ex)
            {
                Log.HandleInternalError("Error getting preference " + ex.Message);
            }
        }

        private void prefCustomizeCriteriaDlgDone(bool result)
        {
            if (result)
            {
                try
                {
                    // set the new criteria values
                    dataGridManager.LoadCriteriaDataset(prefCustomizeCriteriaDlg.gridCriteriaDatasetName);
                    regionLabel.LoadCriteriaDataset(prefCustomizeCriteriaDlg.labelCriteriaDatasetName);
                    regionFill.LoadCriteriaDataset(prefCustomizeCriteriaDlg.fillCriteriaDatasetName);
                }
                catch (Exception ex)
                {
                    Log.HandleInternalError("Error setting preference " + ex.Message);
                }
            }
            ReleaseDialog(CmdPrefCriteria);
        }
    }
}
